package com.example.springbatchdemo.kafka;

import com.alibaba.fastjson.JSONObject;
import com.example.springbatchdemo.config.file.Weather;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.ArrayList;
import java.util.List;

/**
 * @Classname KafkaController
 * @Description TODO
 * @Date 2020/9/26 6:19
 * @Created by kevin
 */
@RestController
@Slf4j
@RequestMapping(value = "/kafka")
public class KafkaController {

    @Autowired
    private KafkaProducer producer;

    @GetMapping(value = "/send")
    public void sendTest() {
        List<Weather> list = new ArrayList<>();

        Weather weather = new Weather();
        for (int i = 0; i < 1000; i++) {
            weather.setId(i + "id");
            weather.setValue(i + "value");
            weather.setType(i + "type");
            weather.setMonth(i + "monnth");
            list.add(weather);
        }
        producer.send(JSONObject.toJSONString(list));
    }
}
